package com.hzhr.iot.device.dao;

import com.hzhr.iot.device.dao.mapper.custom.ImplFactoryEntityCustomMapper;
import com.hzhr.iot.device.dao.mapper.generator.ImplFactoryEntityMapper;
import com.hzhr.iot.device.entity.ImplFactoryEntity;
import com.hzhr.iot.device.entity.ext.ImplFactoryEntityExt;
import com.hzhr.iot.device.queryModel.custom.ImplFactoryCustomQueryModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class ImplFactoryDao {
    @Autowired
    ImplFactoryEntityMapper implFactoryEntityMapper;
    @Autowired
    ImplFactoryEntityCustomMapper implFactoryEntityCustomMapper;

    public int insert(ImplFactoryEntity record) {
        if (record == null) return 0;
        int changeCount = implFactoryEntityMapper.insert(record);
        return changeCount;
    }

    public int delete(ImplFactoryCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = implFactoryEntityCustomMapper.delete(queryModel);
        return changeCount;
    }

    public int update(ImplFactoryEntity record) {
        if (record == null) return 0;
        int changeCount = implFactoryEntityMapper.updateByPrimaryKey(record);
        return changeCount;
    }

    public int updateProps(ImplFactoryCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = implFactoryEntityCustomMapper.updateProps(queryModel);
        return changeCount;
    }

    public ImplFactoryEntity selectEntity(ImplFactoryCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ImplFactoryEntityExt> extList = implFactoryEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<ImplFactoryEntity> selectEntityList(ImplFactoryCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ImplFactoryEntityExt> extList = implFactoryEntityCustomMapper.selectExt(queryModel);
        if (extList == null) return null;
        List<ImplFactoryEntity> entityList = new ArrayList<>();
        for (ImplFactoryEntityExt ext : extList) {
            entityList.add(ext);
        }
        return entityList;
    }
    public ImplFactoryEntityExt selectExt(ImplFactoryCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ImplFactoryEntityExt> extList = implFactoryEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<ImplFactoryEntityExt> selectExtList(ImplFactoryCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ImplFactoryEntityExt> extList = implFactoryEntityCustomMapper.selectExt(queryModel);
        return extList;
    }

    public int selectCount(ImplFactoryCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int count = implFactoryEntityCustomMapper.selectCount(queryModel);
        return count;
    }
}
